
<body>

    <div class="hd">
        <div class="warp">
            <ul class="btn-list">
                <li class="item">

                    <a href="<?php echo $base_url?>home/order/shoppingcar" class="shop-car bg">
                        <!--<div class="num">1</div>-->
                        <i class="icon iconfont icon-icon"></i>
                    </a>
                </li>
                <li  class="item">
                     <!--<a href="./register.html">
                        <i class="iconfont icon-wode"></i>请登录
                    </a>-->
                    <?php if(isset($user)){?>
                    <span href="#" class="bg">
                        <i class="icon iconfont icon-wode"></i><?php echo $user->mobile;?>
                    </span>
                    
                    <ul class="child-item">
                            <li><a href="<?php echo $base_url?>home/order/userorders">我的订单</a></li>
                            <li><a href="<?php echo $base_url?>home/address">收货地址</a></li>
                            <li><a href="<?php echo $base_url;?><?php if(!empty($cardid)){echo 'home/card/cardlist';}else{echo 'home/card/addcard';}?>">绑定银行卡</a></li>
                            <li><a href="<?php echo $base_url?>home/account/logout">退出商城</a></li>
                    </ul>
                    <?php }else{?>
                    <a href="<?php echo $base_url?>home/account/login?back_url=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>">
                        <i class="iconfont icon-wode"></i>请登录
                    </a>
                    <?php }?>
                </li>
            </ul>
            <a href="<?php echo $base_url?>home/goods/index">
            <img src="<?php echo $base_url?>static/dist/images/logo.png" alt="" class="logo-img">
             <span class="span_txt">商城首页</span>
            </a>
        </div>
    </div>


    <div class="prod_details">
        <div class="warp">
            <div class="prod_banner">
                <div class="big-bar">
                    <div class="img-warp">
                        <!--<img src="" alt="">-->
                        <img src="<?php echo $base_path.$info['ads_img']['img_path'][0];?>" alt="">
                    </div>

                </div>
                <div class="sm-bar">
                    <ul>
                    <?php
                    $ads = $info['ads_img'];  
                       
                    if(!empty($ads)){
                        foreach ($ads['img_path'] as $key => $value){     
                    ?>
                        <li>
                            <div class="item">
                                <a href="#">
                                    <img src="<?php echo $base_path.$value;?>" data-src="<?php echo $base_path.$value;?>">
                                </a>
                            </div>
                        </li>
                    <?php }}?>
                        
                    </ul>
                </div>
            </div>
            <div class="prod_detail">
                <p class="name"><?php echo $info['name'];?></p>
                <p class="msg"><?php echo $info['other_name'];?></p>
                <p class="price"> <span>¥</span><?php echo $info['price'];?></p>
                <p class="t_1"><i class="iconfont icon-lingchengben"></i><?php echo isset($activity['activity_desc']) ? $activity['activity_desc'] : '';?></p>
                <!-- <div class="sku">
                    <span class="tit">颜色：</span>
                    <div class="sku-box">
                        <a class="item active" href="#">黄色</a>
                        <a class="item" href="#">蓝色</a>
                    </div>
                </div> -->
                <div class="num-js">
                    <span class="tit">数量：</span>
                    <a href="#" class="sub">
                        <i class="iconfont icon-jian"></i>
                    </a>
                    <input type="number" value="1" class="val_num" autocomplete="off">
                    <a href="#" class="add">
                        <i class="iconfont icon-jia"></i>
                    </a>
                </div>
                <div class="freight">
                    <span class="tit">运费：</span>
                    <span>包邮 <span>¥</span>0</span>
                </div>
                <div class="btn-bar">
                    <a class="addcart">加入购物车</a>
                    <a class="shop <?php if(!isset($user)){?>login<?php }?>" href ="javascript:void(0);" id="<?php if(isset($user)){?>buy<?php }?>">立即购买</a>
                </div>
                <div class="legal">
                    <ul>
                        <li><i class="iconfont icon-ok"></i>零元购</li>
                        <li><i class="iconfont icon-ok"></i>正品保障</li>
                        <li><i class="iconfont icon-ok"></i>总部发货</li>
                    </ul>
                </div>
            </div>
        </div>

    </div>


    <div class="tab_details_box">
        <div class="tab_tit">
            <div class="warp">
                <div class="tit-warp">
                    <a href="#1" class="active">商品详情</a>
                    <a href="#2">商品参数</a>
                </div>
            </div>
        </div>
        <div class="tab_cont">
            <div class="warp">
                <div class="tab_item active">
                    <?php echo $info['goods_detail'];?>
                </div>
                <div class="tab_item">
                    <?php echo $info['goods_params'];?>
                </div>
            </div>
        </div>
    </div>
	<div class="pd-100"></div>

    <?php $this->load->view('home/pc/comm'); ?>


    <div class="login-modal">
        <a href="#13" class="col-btn">
            <i class="icon iconfont icon-icon1"></i>
        </a>
        <div class="tit">
            <a href="#" class="active">账号登录</a>
            <a href="#">新用户注册</a>
            <div class="line"></div>
        </div>
        <div class="cont-box">		
            <!--登录-->
            <div class="cont-item active">
                <div class="input-txt">
                    <i class="iconfont icon-shouji"></i>
                    <input type="text" placeholder="请输入手机号码" id="mobile" name="mobile">
                </div>
                <div class="input-txt">
                    <i class="iconfont icon-suo"></i>
                    <input type="password" placeholder="请输入6-12位密码" id="password" name="password">
                </div>
                <div class="form-ft">
                    <a href="#11" class="login-btn" id="submit">登录</a>
                    <a href="<?php echo $base_url;?>home/account/resetPassword" class="wjmm">忘记密码</a>
                </div>
            </div>
            <!--注册-->
            <div class="cont-item ">
                <div class="input-txt">
                    <i class="iconfont icon-shouji"></i>
                    <input type="text" placeholder="请输入手机号码" id="re_mobile" name="mobile">
                </div>

                <div class="yzm-box2">
                   <div class="input-txt yzm">
                        <input type="text" placeholder="请输入数字验证码" id="captchanum" name="captchanum">
                    </div>
                    <div class="input-txt yzm-btn send-standby sendmsg" id="send-captcha-num">
                        <div id="img" class="am-fr" style=""></div>
                    </div>
                </div>

                <div class="yzm-box">
                    <div class="input-txt yzm">
                        <i class="iconfont icon-anquan"></i>
                        <input type="text" placeholder="请输入验证码"  id="captcha" name="captcha">
                    </div>
                    <div class="input-txt yzm-btn send-standby sendmsg" id="send-captcha">
                        <!--发送验证码-->
                        发送验证码
                    </div>
                </div>
                <div class="input-txt">
                    <i class="iconfont icon-suo"></i>
                    <input type="password" placeholder="请输入6-12位密码"  id="password1" name="password">
                </div>
                <div class="form-ft">
                    <a href="#11" class="login-btn" id="submit1">注册并登录</a>
                    <a href="#111" class="xy">《使用条款和用户协议》</a>
                </div>
            </div>

        </div>
    </div>


    <script src="<?php echo $base_url?>static/dist/js/lib/jquery.min.js"></script>
    <!--<script src="<?php echo $base_url?>static/dist/js/lib/store.legacy.min.js"></script>-->
    
    <script>
        $(function () {
            $(".sm-bar").on('mouseenter', '.item', function () {
                var $this = $(this);
                var imgSrc = $this.find('img').data('src');
                $this.parents('.sm-bar').find('.item').removeClass('active');
                $this.addClass('active')
                $('.big-bar').find('.img-warp img').attr('src', imgSrc);
            })

            $('.tab_tit').on('click', 'a', function () {
                var $this = $(this);
                $this.parents('.tab_tit').find('a').removeClass('active');
                $this.addClass('active');
                var $tab_item = $('.tab_cont').find('.tab_item');
                $tab_item.removeClass('active');
                $tab_item.eq($this.index()).addClass('active');
            })
            // $('.big-bar').find('.img-warp img').attr('src', $('.sm-bar').find('.active img').data('src'));

            $('.login').on('click', function () {
                $('.login-modal').addClass('active');
            })
            $('.col-btn').on('click',function(){
                $('.login-modal').removeClass('active');
            })

            $(".login-modal").on('click', '.tit a', function () {
                var $this = $(this), $contItem = $('.cont-box').find('.cont-item');
                $this.parents('.tit').find('a').removeClass('active');
                $this.addClass('active');
                $contItem.removeClass('active');
                $contItem.eq($this.index()).addClass('active');

                checkLine($this.index())
            })
            function checkLine(index) {
                index = index || 0;
                $(".tit").find('.line').css("left", index * 50 + '%');
            }

            checkLine($(".tit").find('.active').index())

        // ----------------------------------------------------------------
            $('#buy').on('click', function(){
                var selArr=[];
                var selObj = {};
                selObj.goods_id = <?php echo isset($goods_id) ? $goods_id : ''; ?>;                    
                selObj.quantity = $('.val_num').val();
                selArr.push(selObj);
                location.href = "<?php echo $base_url;?>home/order/submitorder?data=" + encodeURI(JSON.stringify(selArr));
            });

        // -------------------------------------------------------------------
            // var cartData = store.get('cartData') || [];
            var cartData = getCookie('cartData') || [];
            var goods_price = "<?php echo $info['price'];?>";
            var goods_id = "<?php echo $info['goods_id'];?>";

            $('.add').on('click',function(){
                var $valNum = $('.val_num');
                var num = parseInt($valNum.val()) || 1;
                $valNum.val(num+1);
            })
            $('.sub').on('click',function(){
                var $valNum = $('.val_num');
                var num = parseInt($valNum.val()) || 1;
                if(num>1){
                    $valNum.val(num-1);                 
                }else{
                    $valNum.val(1); 
                }
            })
             $('body').on('blur','.val_num',function(){
				 console.log('blur')
            	var $this = $(this);
                var num =parseInt($this.val()) || 1
                console.log(num);
                // num<1?$(this).val(1):$(this).val(num);              
                num = num<1?1:num;              				
				num = num > 100000 ? 100000 : num;
				$(this).val(num)
            })
            $('body').on('input','.val_num',function(){
                var $this = $(this);
                var num =parseInt($this.val()) || 1
                console.log(num);
                // num<1?$(this).val(1):$(this).val(num);              
                num = num<1?1:num;              				
				num = num > 100000 ? 100000 : num;
				$(this).val(num)
            })
            //购物车
            if(cartData.length != 0){           
                fillCart();             
            }

            function fillCart() {
                var htmlStr = '';
                var sum = 0, num = 0;
                for (var i = 0; i < cartData.length; i++) {
                    num = parseInt(cartData[i].quantity) || 0;
                    if (num) {
                        sum += num;
                    }
                }
                if (sum >= 100) {
                    sum = '99+'
                }
				if(sum == 0){
					 $('.shop-car').find('.num').addClass('none');
					 
					 return;
				}
                htmlStr = '<div class="num">' + sum + '</div>';
                $numEl = $('.shop-car .num');
                if ($numEl.length == 0) {
                    $('.shop-car').append(htmlStr)
                } else {
                    $numEl.html(sum)
                }
            }
            $('.addcart').on('click',function(){
                var $valNum = $('.val_num');
				$valNum.trigger('blur');
				$valNum = $('.val_num');
                var num = parseInt($valNum.val()) || 1;

                var curData = getCartData(goods_id)
                if(curData){
                    var quantity  = parseInt(curData.quantity) || 0;                
					var sum = quantity+num
                    if(sum>100000){
						sum = 100000
					}
					upCartData(goods_id, 'quantity',sum);

                }else{
					if(num>100000){
						num = 100000
					}
                    cartData.push({
                        id:goods_id,
                        price:goods_price,
                        quantity: num
                    })
                }
                // store.set('cartData',cartData);   
				setCookie('cartData',cartData,2)          
                fillCart();
            })

            function upCartData(id,key,val){                
                for(var i = 0; i<cartData.length;i++){
                    if(cartData[i].id == id){
                        cartData[i][key] = val;
                    }                   
                }   
            }

            function getCartData(id){
                var res = null;
                for(var i = 0; i<cartData.length;i++){
                    if(cartData[i].id == id){
                        res=cartData[i];
                    }                   
                }   
                return res;
            }

        })


        // 登录
        $('#submit').on("click",function() {
            var mobile = $('#mobile').val();
            var password = $('#password').val();

            var pattern = /^1[34578]\d{9}$/;
            if (!pattern.test(mobile)) {
                alert("请填写11位数字的正确号码");
                return;
            }
            if (password == "") {
                alert("请填写密码");
                return;
            }

            //帮助登录
            $.post("<?php echo $base_url; ?>home/account/checkLogin", {
                'mobile': mobile,
                'password': password
            }, function(json) {
                if (json.result == 0) {
                    location.reload();
                } else  {
                    alert("账号或密码错误！");
                }
                return;
            }, 'json');
        });


        // 验证码
        function getCaptcha() {
            $.get("/admin/account/captcha", function (htmlStr) {
                img = '<img id="Imageid" src="/static/captcha/' + htmlStr + '">';
                $("#img").html($(img));
            })
        }
        getCaptcha();

        //刷新验证码
        $('#img').click(function () {
            getCaptcha();
        });

        var iTimer = 0;
        //发送验证码
        $('#send-captcha').on("click",function() {
            var re_mobile = $('#re_mobile').val();
            var captchanum = $('#captchanum').val();

            var pattern = /^1[34578]\d{9}$/;
            if (!pattern.test(re_mobile)) {
                alert("请填写11位数字的正确号码");
                return;
            }
            if (!navigator.onLine) {
                alert("网络连接异常，请检查网络");
                return;
            }
            if (captchanum == "") {
                alert("请填写验证码");
                return;
            }
            var self = this;
            // 验证码
            if ($(this).hasClass("send-standby")) {
                $.post("/home/account/sms_port_pc",{
                    captcha:captchanum,
                    phone:re_mobile,
                    type:0
                }, function (json) {
                    if (json.errcode != 0) { // 检验失败  手机号已存在等
                        alert(json.errmsg);
                        getCaptcha();
                        resetCaptchaBtn();
                    } else { //  发送成功

                        timeCount();
                    }
                }, 'json');
                $(self).removeClass("send-standby");
            }


        });

        function resetCaptchaBtn() {
            clearInterval(iTimer);
            $('#send-captcha').text('发送验证码');
            $('#send-captcha').addClass("send-standby");
        }

        //定时器
        function timeCount() {
            var i = 60;
            iTimer = setInterval(function() {
                i <= 0 ? clearInterval(iTimer) : i--;
                $('#send-captcha').text(i + '秒');
                if (i == 0) {
                    resetCaptchaBtn();
                }
            }, 1000);
        }


        //注册
        $('#submit1').on("click",function() {

            var mobile = $('#re_mobile').val();
            var password1 = $('#password1').val();
            var captcha = $('#captcha').val();
            var pattern = /^1[34578]\d{9}$/;
            if (!pattern.test(mobile)) {
                alert("请填写11位数字的正确号码");
                return;
            }
            if (password1 == "" ||captcha == "") {
                alert("请填写密码和验证码");
                return;
            }

            if(password1.length<6 || password1.length>12){
                alert("请输入6-12位密码");
                return;
            }

            $.post("<?php echo $base_url; ?>/home/account/add", {
                'mobile': mobile,
                'password': password1,
                'captcha': captcha
            }, function(json) {
                var json = eval(json);

                if (json.result == 0) {
                    //帮助登录
                    $.post("<?php echo $base_url; ?>home/account/checkLogin", {
                        'mobile': mobile,
                        'password': password1
                    }, function(json) {
                        if (json.result == 0) {
                            location.reload();
                            return;

                        }
                        return;
                    }, 'json');

                } else {
                    alert(json.message);
                    return;
                }

            }, 'json');
		
        });
		$('.sm-bar').find('li').eq(0).find('.item').addClass('active');		
		function setCookie(cname, cvalue, exdays) {
				cvalue = JSON.stringify(cvalue)

				var d = new Date();
				d.setTime(d.getTime() + (exdays*60*60*1000));
				var expires = "expires="+d.toUTCString();
				document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/";  
			}
			function getCookie(cname) {
				var name = cname + "=";
				var ca = document.cookie.split(';');
				for(var i=0; i<ca.length; i++) {
					var c = ca[i];
					while (c.charAt(0)==' ') c = c.substring(1);
					if (c.indexOf(name) != -1){
						return JSON.parse(c.substring(name.length, c.length));
					} 
				}
				return "";
			}



    </script>
    
</body>

</html>
